<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-hide" id="opt-table-reload" lay-filter="opt-table-reload"></table>
    </div>
</div>
</body>
<script type="text/javascript">
    var layindex,layevent;
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form','formSelects','laydate',"element"], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var formSelects = layui.formSelects
        var exportData = []
        var tableOption = {
            elem: '#opt-table-reload'
            ,url: basePath + '/operation/index'
            ,where:{token:token}
            ,method:"post"
            ,toolbar:commonUtil.toolbarHTML()
            ,title:"操作权限"
            ,defaultToolbar:['filter', 'print']
            ,cols: [[
                { title: '预览',fixed:'left', width:120,templet:function(d){
                    return "<button class='layui-btn "+ d.STYLE+"' lay-event='"+ d.OPERATE_NO+"' _type='"+ d.TYPE+"'  ><i class='layui-icon "+ d.ICON+"'></i>"+ d.OPERATE_NAME+"</button>"
                }}
                ,{field:'OPERATE_NO', title: '编号' ,sort:true,edit:"text" }
                ,{field:'OPERATE_NAME', title: '名称' ,sort:true,edit:"text" }
                ,{field:'STYLE', title: '按钮样式',edit:"text" }
                ,{field:'ICON', title: '图标',edit:"text" }
                ,{field:'ORDER_NUM', title: '排序',edit:"text" ,sort:true }
                ,{field:'MARKS', title: '备注' ,edit:"text"}
            ]]
            ,page: false
            ,height: 'full-50'

        };
        var sourceTable = table.render(tableOption);
        table.on("edit(opt-table-reload)",function(obj){
            var id = obj.data.OPERATE_ID
            var param = {id:id,field:obj.field,value:obj.value,token:token};
            $.getJSON(basePath+"/operation/update",param,function(res){
                if(res.code !=0){
                    layer.msg(res.msg)
                }
                table.reload("opt-table-reload",null)
            } )
        })

        table.on("toolbar(opt-table-reload)",function(obj){
            switch (obj.event){
                case "add":
                    layer.prompt({
                        value: 'New Button 编号',
                        title: '<i class="layui-icon layui-icon-note"></i> 新增按钮',
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function(value, index, elem){
                        var param = {operateNo:value,token:token};
                        $.getJSON(basePath+"/operation/add",param,function(res){
                            if(res.code !=0){
                                layer.msg(res.msg)
                            }
                            table.reload("opt-table-reload",null)
                        } )
                        layer.close(index);
                    });
                    break;
                case "query":
                    break;
            }
        })
    });
</script>
</html>